//
//  LiveCollectionViewCell.m
//  CYWFrame
//
//  Created by Macx on 2017/8/15.
//  Copyright © 2017年 Macx. All rights reserved.
//

#import "LiveCollectionViewCell.h"

#import "Live.h"

@implementation LiveCollectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    CGSize numTextSize = [LZCTools textSizeWithText:@"直播中" font:kUHSystemFontWithSize(10)];
    
    self.cover.frame = CGRectMake(0, 0, SW(2), SW(2));
    self.cover.contentMode = UIViewContentModeScaleAspectFill;
    self.cover.clipsToBounds = YES;
    
    self.state.font = kUHSystemFontWithSize(10);
    self.state.textColor = [UIColor whiteColor];
    self.state.layer.cornerRadius = (numTextSize.height+2)/2;
    self.state.layer.borderColor = [UIColor whiteColor].CGColor;
    self.state.layer.borderWidth = 1;
    self.state.layer.masksToBounds = YES;
    self.state.backgroundColor = RGBA(0, 0, 0, 0.3);
    self.state.frame = CGRectMake(self.cover.width-15-numTextSize.width, 10, numTextSize.width+SW(40), numTextSize.height+4);
    
    CGSize nameSize = [LZCTools textSizeWithText:self.nickname.text font:self.nickname.font];
    
//    self.bottomV.alpha = 0.5;
    self.bottomV.backgroundColor = RGBA(0, 0, 0, 0.2);
    self.bottomV.frame = CGRectMake(0, self.cover.height-10-nameSize.height, self.cover.height, 10+nameSize.height);
    
    self.nickname.text = @"昵称";
    self.nickname.font = kUHSystemFontWithSize(10);
    self.nickname.frame = CGRectMake(5, 5, SW(3)-5, nameSize.height);
    
    self.perNum.font = kUHSystemFontWithSize(10);
    self.perNum.frame = CGRectMake(self.cover.width-5-SW(6), 5, SW(6)-5, nameSize.height);
    
}


- (void)setModel:(Live *)model {
    
    if (_model != model) {
        _model = model;
        
        [self.cover sd_setImageWithURL:[NSURL URLWithString:[model.anchor valueForKey:@"face"]] placeholderImage:[UIImage imageNamed:@"placeHolder"]];
        self.nickname.text = [model.anchor valueForKey:@"nickname"];
        self.perNum.text = [NSString stringWithFormat:@"%@人", [model valueForKey:@"viewer_num"]];
//        if (model.is_live == 1) {
            self.state.text = @"直播中";
//        }
//        else
//            self.state.text = @"未直播";
        
    }
    
}

@end
